package com.interest.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.interest.business.domain.vo.GoodVo;
import com.interest.common.annotation.Log;
import com.interest.common.core.controller.BaseController;
import com.interest.common.core.domain.AjaxResult;
import com.interest.common.core.page.TableDataInfo;
import com.interest.common.enums.BusinessType;
import com.interest.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.interest.business.domain.InterestGoods;
import com.interest.business.service.IInterestGoodsService;

/**
 * 商品Controller
 * 
 * @author ruoyi
 * @date 2024-03-23
 */
@RestController
@RequestMapping("/business/goods")
public class InterestGoodsController extends BaseController
{
    @Autowired
    private IInterestGoodsService interestGoodsService;

    /**
     * 查询商品列表
     */
    @PreAuthorize("@ss.hasPermi('business:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodVo interestGoods)
    {
        startPage();
        List<GoodVo> list = interestGoodsService.selectInterestGoodsList(interestGoods);
        return getDataTable(list);
    }


    /**
     * 获取商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:goods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(interestGoodsService.selectInterestGoodsById(id));
    }

    /**
     * 新增商品
     */
    @PreAuthorize("@ss.hasPermi('business:goods:add')")
    @Log(title = "商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InterestGoods interestGoods)
    {
        return toAjax(interestGoodsService.insertInterestGoods(interestGoods));
    }

    /**
     * 修改商品
     */
    @PreAuthorize("@ss.hasPermi('business:goods:edit')")
    @Log(title = "商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InterestGoods interestGoods)
    {
        return toAjax(interestGoodsService.updateInterestGoods(interestGoods));
    }

    /**
     * 删除商品
     */
    @PreAuthorize("@ss.hasPermi('business:goods:remove')")
    @Log(title = "商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(interestGoodsService.deleteInterestGoodsByIds(ids));
    }
}
